import { ajaxAsync } from 'vue-xiaobu-utils'

/**
 * 绑定微信
 * @param {Stirng} unionId 微信id
 * @param {Stirng} nickName 微信用户名
 * @param {Stirng} openid 微信openid
 * @param {Stirng} country 国家
 * @param {Stirng} province 省
 * @param {Stirng} city 城市
 * @param {Stirng} sex 性别
 * @param {Stirng} headimgurl 头像
 * @param {Boolean} mustBind 强制绑定
 */

function bindWx(
  unionId,
  nickName,
  openid,
  country,
  province,
  city,
  sex,
  headimgurl,
  mustBind = false
) {
  let sendObj = {
    UNION_ID: unionId,
    NICK_NAME: nickName,
    OPEN_ID: openid,
    COUNTRY: country,
    PROVINCE: province,
    CITY: city,
    SEX: sex,
    ICON: headimgurl,
    MUST_BIND: mustBind
  }
  return ajaxAsync('/user/bindwx', sendObj, 1)
}

/**
 * 解除微信绑定
 */

function unBindWx() {
  return ajaxAsync('/user/unbindwx', {})
}

/**
 * 用户微信绑定状态查询
 */

async function getBindState() {
  let res = await ajaxAsync('/user/bindwxState', {})
  console.log(res)
  if (res.BIND_STATUS === 0 || res.BIND_STATUS === '0') {
    return res
  } else {
    return ''
  }
}

export { bindWx, unBindWx, getBindState }
